/*
 * analog_con.c
 *
 * Created: 2012-08-24 17:48:39
 *  Author: Antrykot
 */ 

#include "../sc-k/main.h"
#include "../sc-k/utils.h"
#include "../sc-k/analog.h"
#include "../sc-k/trans-k.h"
#include "../sc-k/sc-k.h"
#include "../sc-k/digital.h"


void calc_freq()
{
	if (wait_spec)
	return;
	
	if (in_kalib)
	{
		freq = 3000;
		return;
	}
	
	u16 pom = measurment;
	
	if (pom & 0x4000)	//14bit
	{
		pom &= 0x1FFF;
		if (pom & 0x1000)	//minus - 12bit
		{
			pom &= 0x0FFF;

			freq = 10200;
			return;
		}
		
	
		freq = 9994 - (pom * 20);

		if (freq < 5000)
		freq = 4800;
		return;
	}
	
	freq = 4500;		// ERROR ?
}

